﻿@model Telerik.Web.Mvc.GridModel<ScheduleTaskModel>
@using Telerik.Web.Mvc.UI;
@using System.Linq;
@{
    //page title
    ViewBag.Title = T("Admin.System.ScheduleTasks").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/subsites/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.System.ScheduleTasks")
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            <strong>@T("Admin.System.ScheduleTasks.RestartApplication")</strong>
        </td>
    </tr>
    <tr>
        <td>
            @(Html.Telerik().Grid(Model.Data)
                    .Name("schedule-tasks-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("Id");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Name);
                        columns.Bound(x => x.Seconds);
                        columns.Bound(x => x.Enabled)
                            .Template(
                                @<img alt="" src="@Url.Content("~/subsites/Administration/Content/images/active-" + item.Enabled.ToString().ToLowerInvariant() + ".gif")" />
                            )
                            .ClientTemplate("<img alt='' src='" + Url.Content("~/subsites/Administration/Content/images/") + "active-<#= Enabled #>.gif' />")
                            .Centered()
                            .Width(100);
                        columns.Bound(x => x.StopOnError)
                            .Template(
                                @<img alt="" src="@Url.Content("~/subsites/Administration/Content/images/active-" + item.StopOnError.ToString().ToLowerInvariant() + ".gif")" />
                            )
                            .ClientTemplate("<img alt='' src='" + Url.Content("~/subsites/Administration/Content/images/") + "active-<#= StopOnError #>.gif' />")
                            .Centered()
                            .Width(100);
                        columns.Bound(x => x.LastStartUtc).ReadOnly();
                        columns.Bound(x => x.LastEndUtc).ReadOnly();
                        columns.Bound(x => x.LastSuccessUtc).ReadOnly();
                        columns.Command(commands =>
                        {
                            commands.Edit().Text(T("Admin.Common.Edit").Text);
                        }).Width(180).Title(T("Admin.Common.Edit").Text);

                    })
                    .Editable(x =>
                    {
                        x.Mode(GridEditMode.InLine);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("List", "ScheduleTask")
                            .Update("TaskUpdate", "ScheduleTask");
                    })
                    .ClientEvents(x => x.OnError("grid_onError"))
                    .EnableCustomBinding(true))
            <script type="text/javascript">
                function grid_onError(e) {
                    alert(e.XMLHttpRequest.responseText);
                    e.preventDefault();
                }
            </script>
        </td>
    </tr>
</table>
